<script type="text/javascript">        

$(document).ready(function(){                                  

    $("#suppliers_select").change(function(){
        window.location.href = '<?=site_url('admin/suppliers/view/')?>/' + $(this).val();
    });  

    $(".cancel_trigger").click(function(){   
        <? if ($standalone==false){ ?>
        window.location.href = '<?=site_url('admin/suppliers/view/'.$item["id_Supplier"])?>';
        <? } else { ?>
        window.opener.focus();
        window.close();
        <? } ?>
    });

});

</script>

<div id="content">     

<? if($this->input->post("submit_action") !== FALSE){ ?>
    <div class="response"><?=validation_errors()?></div>                
<? } ?>

<? if(($standalone==false)&&($action!=="create")) { ?>
    <div class="float_block_right">
        Select a supplier: &nbsp;
        <select id="suppliers_select" class="float_right" style="min-width:150px">
        <? foreach($list as $supl){?>  
            <option value="<?=$supl["id_Supplier"]?>" <?if($supl["id_Supplier"]==$item["id_Supplier"]) print ' selected="selected"'?>><?=$supl["Name_Supplier"]?></option>
        <? } ?>
        </select>
        <a class="button" href="<?=site_url('admin/suppliers')?>" style="float:right; margin-left:5px">BACK TO LIST</a>
    </div>
<? } ?>


    <h1><?=($action == 'update') ? "Edit supplier" : "Add new supplier" ?></h1>
           

    <form action="" method="post">

    <div style="width:350px" class="float_block">

        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">Company</h4>       
            <input type="text" style="width:220px" class="text_input" name="name" maxlength="250" value="<?=set_value('name', $item['Name_Supplier'])?>" />
        </div>  

        <div style="width: 100%;" class="float_block">
            <h4 style="float:left; width:110px;">Supplier code</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="code" maxlength="250" value="<?=set_value('code', $item['Code_Supplier'])?>" />
        </div>  

        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">Contact Name</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="contact_name" maxlength="250" value="<?=set_value('contact_name', $item['ContactName_Supplier'])?>" />
        </div>

        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">Email</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="email" maxlength="250" value="<?=set_value('email', $item['Email_Supplier'])?>" />
        </div>

        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">Phone</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="phone" maxlength="250" value="<?=set_value('phone', $item['Phone_Supplier'])?>" />
        </div>
    
        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">Fax</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="fax" maxlength="250" value="<?=set_value('fax', $item['Fax_Supplier'])?>" />
        </div>             
    
        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">Mobile</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="mobile" maxlength="250" value="<?=set_value('mobile', $item['Mobile_Supplier'])?>" />
        </div>

        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">Website</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="website" maxlength="250" value="<?=set_value('website', $item['WebSite_Supplier'])?>" />
        </div>                    
    
    </div>


    <div style="width:350px; margin-right:20px" class="float_block">

        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">Address</h4>                                    
            <textarea style="height:56px; width:220px" name="address"><?=set_value('address', $item['Address_Supplier'])?></textarea>
        </div>                 

        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">City</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="city" maxlength="250" value="<?=set_value('city', $item['City_Supplier'])?>" />
        </div>                 

        <div style="width: 100%;" class="float_block">                    
            <h4 style="float:left; width:110px;">State</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="state" maxlength="250" value="<?=set_value('state', $item['State_Supplier'])?>" />
        </div>                 

        <div style="width: 100%;" class="float_block">                      
            <h4 style="float:left; width:110px;">Post Code</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="postcode" maxlength="250" value="<?=set_value('postcode', $item['PostCode_Supplier'])?>" />
        </div>                 

        <div style="width: 100%;" class="float_block">                     
            <h4 style="float:left; width:110px;">Country</h4>                                    
            <input type="text" style="width:220px" class="text_input" name="country" maxlength="250" value="<?=set_value('country', $item['Country_Supplier'])?>" />
        </div>                 

        <div style="width: 100%;" class="float_block">                  
            <h4 style="float:left; width:110px;">Address 2</h4>                                    
            <textarea style="height:56px; width:220px" name="address2"><?=set_value('address2', $item['Address2_Supplier'])?></textarea>
        </div>                 

    </div>

    <div class="content_block">
        <a href="#" class="button cancel_trigger">CANCEL</a>
        <input name="submit_action" type="hidden" value="<?=$action?>" />
        <input type="hidden" name="token" value="<?=$token?>" />        
        <input type="hidden" name="supplier_id" value="<?=$item["id_Supplier"]?>" />        
        <input type="hidden" name="standalone" value="<?=$standalone?>" />        
        <input class="button" type="submit" value="SAVE" />        
    </div>

    </form>

    <? if($standalone==false) print modules::run("_admin/_suppliers/supplier_products", $item["id_Supplier"])?>

</div>